/**
 * 公共参数封装
 * @Author: linzy
 * @Date: 2022-05-24
 * @function useConstants
 * @property {string} FILE_SERVER - 文件路径
 * @property {string} H5_HOST - h5网址路径
 * @property {string} ENV_TAG - 环境变量
 * @property {string} ROOT_URL - 后台根目录
 * <caption>返回的对象</caption>
 * @example
 * import { useConstants } from "@/hooks";
 * const { FILE_SERVER } = useConstants();
 */
import { useMemo } from "react";
const MAIN_HOST = "idongjia.cn";
export default () => {
  const constants = useMemo(() => {
    const ENV_TAG = window.location.host.includes(MAIN_HOST)
      ? window.location.host.split(".")[0].split("-")[1] || ""
      : process.env.DEV_TYPE;
    return {
      ENV_TAG,
      FILE_SERVER: `${window.location.protocol}//file${ENV_TAG ? "-" + ENV_TAG : ""
        }.idongjia.cn/`,
      ROOT_URL: `${window.location.protocol}//admin${ENV_TAG ? "-" + ENV_TAG : ""
        }.${MAIN_HOST}/`,
      H5_HOST: `${window.location.protocol}//m.idongjia.cn/${ENV_TAG ? ENV_TAG + "/" : ""
        }`,
    };
  }, []);
  return constants;
};
